const fs = require("fs")
const path = require("path")

// 生成写入流
function mCreateWriteStream(fileName) {
  // 指定写入文件的路径
  const fullFileName = path.join(__dirname, "../", "../", "logs", fileName)

  // 创建写入流 且方式为追加写入
  const writeStream = fs.createWriteStream(fullFileName, { flags: "a" })

  // 返回写入流
  return writeStream
}

// 写入日志
function writeLog(writeStream, log){
  writeStream.write(log + "\n")
}

const accessWriteStream = mCreateWriteStream("access.log")
function access (log) {
  writeLog(accessWriteStream, log)
}

module.exports = {
  access
}
